package com.sky.d_thread;
/**
 * Priority 美 [praɪˈɔ:rəti]
 * 优先 
 * 
 * 六有：有理想、有追求、有担当、有作为、有品质、有修养
 * @Author:hjt
 */
public class PriorityDemo {

	public static class HeightPriority extends Thread{

		static int count = 0;
		@Override
		public void run() {
			while (true) {
				synchronized (PriorityDemo.class) {
					count ++;
					if(count > 1000000){
						System.out.println("HeightPriority is completed!");
						break;
					}
				}
			}
		}
	}
	
	public static class LowPriority extends Thread{

		static int count = 0;
		@Override
		public void run() {
			while (true) {
				synchronized (PriorityDemo.class) {
					count ++;
					if(count > 1000000){
						System.out.println("LowPriority is completed!");
						break;
					}
				}
			}
		}
	}
	
	public static void main(String[] args) {
		Thread height = new HeightPriority();
		Thread low = new LowPriority();
		height.setPriority(Thread.MAX_PRIORITY);
		low.setPriority(Thread.MIN_PRIORITY);
		
		low.start();
		height.start();
		
	}
	
	/**
	//The minimum priority that a thread can have.
    public final static int MIN_PRIORITY = 1;

   //The default priority that is assigned to a thread.
    public final static int NORM_PRIORITY = 5;

   // The maximum priority that a thread can have.
    public final static int MAX_PRIORITY = 10;
	
	
	线程的优先级范围：1-10
	高优先级的不一定先执行，只是在抢占CPU资源的时候，高优先级的线程更容易在竞争中胜出
	 * */
}
